/*
 * ExSysDataDef.h
 *
 *  Created on: 2015-2-6
 *      Author: zhangyu
 */

#ifndef EXSYSDATADEF_H_
#define EXSYSDATADEF_H_

//-----------------------Global Data for user---------------------------
//-----------------------Global defines---------------------------------
/*
 * FIRMWARE_VER_NUM define:
 * Client Class: 1-> HG
 * Version: 01 version
 * */
#define	FIRMWARE_VER_NUM		0x10

//-------------------ETH Data Defines-----------------------------------
#define DEV_TYPE_CLASS			0x30		// 0x10 -> 电池柜1， 0x11 -> 电池柜2
/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
#define MAC_ADDR0   			0x68
#define MAC_ADDR1   			0xF7
#define MAC_ADDR2   			0x28
#define MAC_ADDR3   			0xB4
#define MAC_ADDR4   			0x16
#define MAC_ADDR5   			(0x28+DEV_TYPE_CLASS)

#define MAC_ADDR0_RDNC   		0x44
#define MAC_ADDR1_RDNC   		0x4C
#define MAC_ADDR2_RDNC   		0x4C
#define MAC_ADDR3_RDNC   		0x4B
#define MAC_ADDR4_RDNC   		0x22
#define MAC_ADDR5_RDNC   		(0x28+DEV_TYPE_CLASS)

/***********************Static IP ADDRESS: IP_ADDR0.IP_ADDR1.IP_ADDR2.IP_ADDR3 *********************/
#define IP_ADDR0   				10
#define IP_ADDR1  	 			0
#define IP_ADDR2   				(1 + DEV_TYPE_CLASS - 0x30)
#define IP_ADDR3   				6

#define IP_ADDR0_RDNC   	10
#define IP_ADDR1_RDNC 		0
#define IP_ADDR2_RDNC			8
#define IP_ADDR3_RDNC			81

/*NETMASK*/
#define NETMASK_ADDR0   		255
#define NETMASK_ADDR1   		255
#define NETMASK_ADDR2   		0
#define NETMASK_ADDR3   		0

#define NETMASK_ADDR0_RDNC 		255
#define NETMASK_ADDR1_RDNC 		255
#define NETMASK_ADDR2_RDNC 		255
#define NETMASK_ADDR3_RDNC 		0

/*Gateway Address*/
#define GW_ADDR0   				10
#define GW_ADDR1   				0
#define GW_ADDR2   				1
#define GW_ADDR3   				254

#define GW_ADDR0_RDNC			10
#define GW_ADDR1_RDNC			0
#define GW_ADDR2_RDNC			8
#define GW_ADDR3_RDNC			254

/*************************************Net work configure end*****************************************/
/*Communication port define*/
#define UDP_TRDP_PD_PORT		17224


/*---------CAN Config----------*/
#define CAN1_COM_BANDRATE		250
#define CAN1_ID_TYPE			0		//1:extend CAN ID, 0:stander CAN ID
#define CAN2_COM_BANDRATE		250
#define CAN2_ID_TYPE			0

/*------------------------------*/
#define UARTB_COM_BANDRATE		230400
#define UARTC_COM_BANDRATE		230400

/*--------TRDP Mode------------*/
#define WKS_MainTRDP			(0)
#define WKS_SlaveTRDP			(1)

//-----------------------Global Enums-----------------------------------
// ExSystem's ErrorCode for LESs display
typedef enum  {
	ERR_OS_INTERNAL_TIMING = 0,				//OS TASK Dispatch error
	ERR_PARAM,								//PARAM error
	ERR_EPM,								//EEPROM1 Error
	ERR_RTC,								//AI internal ERROR
	ERR_ETH,								//Eth Error
	ERR_CAN,								//CAN initialize error
	ERR_MAX_CNT								//Err max number
} ERR_CODE;

//Eth CMD ID
typedef enum {
	ID_None = 0,
	ID_SetTime,							//set device time
	ID_Reset,							//restart the device
	ID_MAX_CNT
}MSG_ID;

//TASK Message Data structure define
typedef union DataType{
   uint8_t 	byte[4];					//bytes
   int16_t 	iWord[2];					//signed word
   uint16_t	uWord[2];					//unsigned word
   uint32_t	uDWord;						//unsigned DWord
   int32_t	iDWord;						//signed Dword
}DataType;

//Message frame structure define
typedef struct  MSG_TYPE{
     uint16_t  	MSG_ID;					//Message ID -> MSG_I
     uint16_t  	MSG_Cmd;				//Message CMD -> user define
     DataType  	MSG_Data;				//Message Data -> DataType
}MSG_TYPE;

//variables for EEPROM 48 bytes
typedef struct EE_PARA_REGS{
	uint32_t	boot_pwd;				/*enable boot to app when this value = 0x5500FFAA */

	uint8_t		IP_ADDR[4];				/*IP Address : need reset*/
	uint8_t		NETMASK_ADDR[4];		/*Net Mask Address : need reset*/
	uint8_t		GW_ADDR[4];				/*GW Address : need reset*/
	uint8_t		MAC_ADDR[6];			/*MAC Address : need reset*/
	
	uint8_t		IP_ADDR_RDNC[4];					/*IP RDNC Address*/
	uint8_t		NETMASK_ADDR_RDNC[4];				/*Net Mask RDNC Address*/
	uint8_t		GW_ADDR_RDNC[4];					/*GW RDNC Address*/
	uint8_t		MAC_ADDR_RDNC[6];					/*MAC RDNC Address*/
	
	uint16_t	CAN1_Bandrate;						/*CAN BAND RATE : need reset*/
	uint16_t	CAN2_Bandrate;						/*RS485 bandrate : need reset*/

	uint8_t		md5_chk_value[16];		//download file's MD5 value check
	uint32_t	file_size;				//the app firmware file bytes size
	uint32_t	crc_value;				//store value part's crc value
}EE_PARA_REGS;										//164 Byte


//variables for user
typedef struct SYS_USER_REGS{
	EE_PARA_REGS		MR_Para;
	uint32_t			CPU_Sn[3];						/*CPU UID*/
	uint32_t			ErrState;						/*every bit for one kind of error*/
	uint16_t			UIDValue;						//CPU Sn's CRC Check Value
	uint16_t			curEthMode;						//current Ethernet mode
}SYS_USER_REGS;
//----------------------------------------------------------------------
extern __IO SYS_USER_REGS * const p_gSysUserRegs;	//pointer to User Data

#endif /* EXSYSDATADEF_H_ */
